package jdbc;

import jdbc.common.InputUtil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Scanner;

public class RegUserDemo {
    public static void main(String[] args) throws Exception{
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo());
        System.out.println(userInfo);
        Connection connection = DBUtil.getConnection();
        Statement statement = connection.createStatement();
        String sql = "INSERT INTO userinfo (username, password, nickname, age) " +
                     "VALUES ('"+userInfo.getUserName()+"','"+userInfo.getPassWord()+"','"+userInfo.getNickName()+"',"+userInfo.getAge()+") ";
        int num = statement.executeUpdate(sql);
        System.out.println(num > 0 ? "注册成功" : "注册失败");
        connection.close();
    }
}
